/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    database: 'graduation',
    username: 'root',
    password: 'Zqk980823',
    timezone: '+08:00',
    define: {
      underscored: true, // 注意需要加上这个， egg-sequelize只是简单的使用Object.assign对配置和默认配置做了merge, 如果不加这个 update_at会被转变成 updateAt故报错
      // 禁止修改表名，默认情况下，sequelize将自动将所有传递的模型名称（define的第一个参数）转换为复数
      // 但是为了安全着想，复数的转换可能会发生变化，所以禁止该行为
      freezeTableName: true,
      timestamps: false, // 去除createAt updateAt
    },
  };
  config.redis = {
    client: {
      port: 6379, // Redis port
      host: '127.0.0.1', // Redis host
      password: 'Zqk980823',
      db: 0,
    },
  };

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1584154751587_388';

  // add your middleware config here
  config.middleware = [ 'auth' ];
  config.auth = {
    enable: true,
    ignore: [
      '/api/v1/home',
      '/api/v1/user/login',
      '/api/v1/user/getCode',
      '/api/v1/user/telLogin',
      '/api/v1/user/regTel',
      '/api/v1/user/register',
      '/api/v1/product',
    ],
  };
  // 配置上传
  config.multipart = {
    mode: 'stream',
    fileExtensions: [ '.png', '.jpg', '.jpeg' ], // 扩展几种上传的文件格式
  };
  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  config.cluster = {
    listen: {
      path: '',
      port: 6688,
      hostname: '127.0.0.1',
    },
  };

  // config.passportJwt = {
  //   secret: 'zengqingkang',
  // };
  config.jwt = {
    secret: 'zengqingkang',
  };
  // 安全配置 （https://eggjs.org/zh-cn/core/security.html）
  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
    },
    // 允许访问接口的白名单
    domainWhiteList: [ 'http://127.0.0.1:6688' ],
  };
  // 跨域配置
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };
  config.logger = {
    level: 'DEBUG',
    outputJSON: true,
    encoding: 'utf-8',
    consoleLevel: 'DEBUG',
  };

  // config.session = {
  //   key: 'SESSION_KEY',
  //   maxAge: 1000 * 60 * 30,
  //   httpOnly: false,
  //   encrypt: true,
  //   signed: true,
  //   renew: true,
  // };
  exports.assets = {
    publicPath: 'http://localhost:6688/public/',
  };
  return {
    ...config,
    ...userConfig,
  };
};
